<!--
 * @Description: 工资统计
 * 
 * @Author: XiongYaoYuan<xiongyaoyuan>
 * @Date: 2023-08-10 17:03:32
 * @FilePath: /yuxiuproweb/src/views/money/wage/index.vue
-->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="日期：" prop="type">
        <el-radio-group v-model="queryParams.type">
          <el-radio label="1">按月</el-radio>
          <el-radio label="2">自定义</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="" prop="yearMonth" v-show="queryParams.type === '1'">
        <el-date-picker
          clearable
          v-model="queryParams.yearMonth"
          type="month"
          value-format="yyyy-MM"
          placeholder="请选择月"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item
        label=""
        prop="startAndEnd"
        v-show="queryParams.type === '2'"
      >
        <el-date-picker
          clearable
          v-model="queryParams.startAndEnd"
          type="daterange"
          style="width: 300px"
          value-format="yyyy-MM-dd"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['md:order:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="recordList"
      :max-height="maxHeight + 50"
      border
    >
      <el-table-column type="index" width="55" align="center" />
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="编号" align="center" prop="userId">
        <template slot-scope="{ row }">
          <el-link
            type="primary"
            @click="
              () => {
                detail = {
                  show: true,
                  data: {
                    ...row,
                  },
                  queryParams,
                };
              }
            "
            >{{ row.userId }}</el-link
          >
        </template>
      </el-table-column>
      <el-table-column label="名称" align="center" prop="nickname" />
      <el-table-column label="数量" align="center" prop="quantity">
        <template slot-scope="{ row }">
          {{ getSubtotal(row.quantity) }}
        </template>
      </el-table-column>
      <el-table-column label="小计" align="center" prop="subtotal">
        <template slot-scope="{ row }">
          {{ getSubtotal(row.subtotal) }}
        </template>
      </el-table-column>
      <el-table-column label="奖金" align="center" prop="awardAmount" />
      <el-table-column
        label="扣款"
        align="center"
        prop="punishmentAmount"
      ></el-table-column>
      <el-table-column label="合计" align="center" prop="sum"></el-table-column>
      <!-- <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['pro:record:edit']"
              >修改</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['pro:record:remove']"
              >删除</el-button
            >
          </template>
        </el-table-column> -->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 详情 -->
    <detail-view
      v-if="detail.show"
      :show.sync="detail.show"
      v-bind="detail"
    ></detail-view>
  </div>
</template>

<script>
import { listWorkerWageStatistic } from "@/api/money/wage";
import DetailView from "./mods/detail.vue";
import commonMix from "@/utils/mixins/common";

export default {
  mixins: [commonMix],
  name: "Record",
  components: {
    DetailView,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 交易记录表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        type: "1",
        yearMonth: null,
        startDate: null,
        endDate: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      detail: {
        show: false,
        data: null,
      },
    };
  },
  created() {
    this.queryParams.yearMonth = this.parseTime(new Date(), "{y}-{m}");
    this.getList();
  },
  methods: {
    /** 查询交易记录列表 */
    getList() {
      this.loading = true;
      const params = {
        ...this.queryParams,
        type: undefined,
        yearMonth:
          this.queryParams.type === "1"
            ? this.queryParams.yearMonth
            : undefined,
        startDate:
          this.queryParams.type === "2"
            ? this.queryParams.startAndEnd?.[0]
            : undefined,
        endDate:
          this.queryParams.type === "2"
            ? this.queryParams.startAndEnd?.[1]
            : undefined,
        startAndEnd: undefined,
      };
      console.log(params);

      listWorkerWageStatistic(params).then(({ data }) => {
        this.recordList = data;
        // this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        transactionRecordId: null,
        orderId: null,
        clientId: null,
        clientName: null,
        cashAccount: null,
        rebateAccount: null,
        otherAccount: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getSubtotal(subtotal) {
      return subtotal ? subtotal.toFixed(2) : "0";
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      const params = {
        ...this.queryParams,
        type: undefined,
        yearMonth:
          this.queryParams.type === "1"
            ? this.queryParams.yearMonth
            : undefined,
        startDate:
          this.queryParams.type === "2"
            ? this.queryParams.startAndEnd?.[0]
            : undefined,
        endDate:
          this.queryParams.type === "2"
            ? this.queryParams.startAndEnd?.[1]
            : undefined,
        startAndEnd: undefined,
      };
      this.download(
        "pro/record/exportWorkerWageStatistic",
        {
          ...params,
        },
        `wage_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
